package io.xxx.xbutler.domain.task;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.xxx.xbutler.domain.Store;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.ibatis.type.EnumTypeHandler;

import java.time.LocalDateTime;

@Data
@Accessors(chain = true)
public class TaskReceiver {

    @TableId
    private Long id;

    private Long taskId;

    private Long storeId;

    private String storeCode;

    private String storeName;

    @TableField(typeHandler = EnumTypeHandler.class)
    private ReceiverType receiverType;

    private String receiverId;

    private String receiverSerialNo;

    private String receiverName;

    private LocalDateTime pushTime;

    private Boolean pushed;

    private LocalDateTime createdTime;

    private LocalDateTime updatedTime;

    public Receiver toReceiver(Store store) {
        Receiver receiver = new Receiver();
        receiver.setType(receiverType);
        receiver.setId(receiverId);
        receiver.setSerialNo(receiverSerialNo);
        receiver.setName(receiverName);
        if (store != null) {
            receiver.setStoreId(store.getId());
            receiver.setStoreCode(store.getCode());
            receiver.setStoreName(store.getName());
            receiver.setStoreStatus(store.getStatus());
        }
        return receiver;
    }
}
